<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/headeradmin.php");
?>

<section>
<hgroup>
<h1>Gebouw-details beheren</h1>
</hgroup>

Klik <a href="gebouwdetailoverzichttoevoegen.php">hier</a> om een detail-veld van een gebouw toe te voegen.
                    <br><br>
                    
                    <?php
                    if (isset($_GET['start'])) { // If we are no longer on the first page, $_GET['start'] will be known and it's value will be saved in $start
                        $start = $_GET['start'];
                    } else { // If we are still on the first page, $_GET['start'] will be unknown and a value of 0 will be saved in $start
                        $start = 0;
                    }

                    if (strlen($start) > 0 and !is_numeric($start)) { // A check on the value of $start
                        exit;
                    }
                    $eu = ($start - 0);
                    $limit = 20; // Number of records shown on each page
                    $thi = $eu + $limit;
                    $back = $eu - $limit;
                    $next = $eu + $limit;
                    $page_name = "gebouwdetailoverzicht.php?";
                    $nume = GetAllBuildingSpecCount();
                    ?>

                    <table id="rounded-corner">
                        <thead>
                            <tr>
                                <th scope="col" class="rounded-company">Veld</th>
                                <th scope="col" class="rounded-q1">Commentaar</th>
                                <th scope="col" class="rounded-q2">Status</th>
                                <th scope="col" class="rounded-q2">Verplicht</th>
                                <th scope="col" class="rounded-q3">Bewerken</th>
                                <th scope="col" class="rounded-q4">Deactiveren</th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <td colspan="4" class="rounded-foot-left">
                                    <?php
                                    if ($limit < $nume) { // Creating the links for the different pages
                                        if ($back >= 0) {
                                            echo "<a href=" . $page_name . "start=" . $back . ">Vorige</a>";
                                        }
                                        $i = 0;
                                        $l = 1;
                                        for ($i = 0; $i < $nume; $i = $i + $limit) {
                                            if ($i <> $eu) {
                                                echo " <a href=" . $page_name . "start=" . $i . ">$l</a> ";
                                            } else {
                                                echo "<span style=\"font-weight:bold;\">" . $l . "</span>";
                                            }
                                            $l = $l + 1;
                                        }
                                        if ($thi < $nume) {
                                            echo "<a href=" . $page_name . "start=" . $next . ">Volgende</a>";
                                        }
                                    }
                                    ?>
                                </td>
                                <td class="rounded-foot-right">&nbsp;</td>
                            </tr>
                        </tfoot>
                        <tbody>
                            <?php
                            // Getting all the records for a specific page
                            $getAllBuildingSpec = GetAllBuildingSpecLimit($eu, $limit);
                            while ($buildingspecRow = mysql_fetch_array($getAllBuildingSpec)) {

                                echo "<tr><td>" . $buildingspecRow['BuildingKey']."</td>";
                                echo "<td>" . $buildingspecRow['Comment']."</td>";
                                
                                if ($buildingspecRow['Activated'] == "T")
                                {
                                    echo "<td>Geactiveerd</td>";
                                }
                                else
                                {
                                    echo "<td>Gedeactiveerd</td>";
                                }
                                
                                if ($buildingspecRow['Required'] == "T")
                                {
                                    echo "<td>Verplicht</td>";
                                }
                                else
                                {
                                    echo "<td>Niet verplicht</td>";
                                }
                                
                                
                                
                                
                                if (isset($_GET['start'])) {
                                    echo "<td><a href=\"gebouwdetailbewerken.php?id=" . $buildingspecRow['Id'] . "&start=" . $_GET['start'] ."\" >Bewerken</a></td>";
                                    if ($buildingspecRow['Activated'] == "T")
                                    {
                                        echo "<td><a href=\"gebouwdetaildeactiveren.php?id=" . $buildingspecRow['Id'] . "&start=" . $_GET['start'] . "\" >Deactiveren</a></td>";
                                    }
                                    else
                                    {
                                        echo "<td><a href=\"gebouwdetailactiveren.php?id=" . $buildingspecRow['Id'] . "&start=" . $_GET['start'] . "\" >Activeren</a></td>";
                                    }
                                } else {
                                    echo "<td><a href=\"gebouwdetailbewerken.php?id=" . $buildingspecRow['Id'] . "\" >Bewerken</a></td>";
                                    if ($buildingspecRow['Activated'] == "T")
                                    {
                                        echo "<td><a href=\"gebouwdetaildeactiveren.php?id=" . $buildingspecRow['Id'] . "\" >Deactiveren</a></td>";
                                    }
                                    else
                                    {
                                        echo "<td><a href=\"gebouwdetailactiveren.php?id=" . $buildingspecRow['Id'] . "\" >Activeren</a></td>";
                                    }
                                }
                            }
                            ?>
                        </tbody>
                    </table>

</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>